package com.zzptc.tkfate;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ListView listView;
    List<Student>list_lv;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView=findViewById(R.id.lv_lv);
        list_lv=new ArrayList<>();
        for (int i=0;i<100;i++){
            Student student = new Student(R.mipmap.ic_launcher,i,"姓名"+i,new Date()+"");
            list_lv.add(student);
        }
        for (Student s:list_lv){
            Log.d(TAG,s.getName());
        }
        MyAdapter myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);
    }
    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return list_lv.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Student student = list_lv.get(position);
            View view1 = View.inflate(MainActivity.this,R.layout.item,null);
            ImageView iv_pic = view1.findViewById(R.id.iv_pic);
            iv_pic.setImageResource(R.mipmap.a1);
            TextView iv_id = view1.findViewById(R.id.iv_id);
            iv_id.setText(student.getId()+"");
            TextView iv_name = view1.findViewById(R.id.iv_name);
            iv_name.setText(student.getName());
            TextView iv_date = view1.findViewById(R.id.iv_date);
            iv_date.setText(student.getTime());
            return view1;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.myoption,menu);

        //menu.add(0,1,1,"关于");
        //menu.add(0,2,2,"账号");

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        //Toast.makeText(this,""+item.getItemId(),Toast.LENGTH_SHORT).show();
        if (item.getItemId()==1){
            Toast.makeText(this, "你点击了关于", Toast.LENGTH_SHORT).show();
        }

        return true;
    }
}
